/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package smartclient.client;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author Paolo
 */
public class QuoteSealed {
    private Integer index;
    private String digest;


    public QuoteSealed(int index, Object digest) {
        this.index = index;
        this.setDigest(digest);
    }
    /**
     * @return the index
     */
    public Integer getIndex() {
        return index;
    }

    /**
     * @param index the index to set
     */
    public void setIndex(int index) {
        this.index = index;
    }

    /**
     * @return the digest
     */
    public String getDigest() {
        return digest;
    }

    /**
     * @param digest the digest to set
     */
    public void setDigest(Object digest) {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        ObjectOutputStream oOut;
        try {
                oOut = new ObjectOutputStream(output);
                oOut.writeObject(digest);
        } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        }

        try{
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(output.toByteArray());
            byte messageDigest[] = algorithm.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i=0;i<messageDigest.length;i++) {
                    hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }
            //System.out.println(this + " in md5 \n"+hexString.toString());
            this.digest = hexString.toString();

        }catch(NoSuchAlgorithmException nsae){}
    }

    

}
